package com.gxa.modules.app.outpatient.medical.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.gxa.modules.app.outpatient.medical.dto.*;
import com.gxa.modules.app.outpatient.medical.service.MedicalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "体检预约记录")
@RestController
@RequestMapping("/app/medicalPerson")
public class MedicalRecordController {
    @Autowired
    private MedicalService medicalService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "患者id", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "StartTime", value = "开始时间", dataType = "Date"),
            @ApiImplicitParam(paramType = "query", name = "EndingTime", value = "结束时间", dataType = "Date"),
            })
    @ApiOperation("查询体检预约信息")
    @PostMapping("/selectByPatientId")
    public R selectByPatientId(@RequestParam("id") Integer id, @RequestParam("StartTime") Date StartTime, @RequestParam("EndingTime") Date EndingTime){
        List<RecordDto> recordDtos = this.medicalService.selectByPatientId(id, StartTime, EndingTime);
        return R.ok(recordDtos);
    }

    @ApiImplicitParam(paramType = "path", name = "id", value = "患者id", dataType = "int")
    @ApiOperation("查询报告")
    @PostMapping("/selectMaxById/{id}")
    public R selectMaxById(@PathVariable("id") Integer id){
        ReportInformationDto reportInformationDto = this.medicalService.selectMaxById(id);
        return R.ok(reportInformationDto);
    }

    @ApiImplicitParam(paramType = "path", name = "id", value = "报告id", dataType = "int")
    @ApiOperation("查询体检报告详细信息的所属项目")
    @PostMapping("/selectReportById/{id}")
    public R selectReportById(@PathVariable("id") Integer id){
        List<ItemDto> strings = this.medicalService.selectByReportId(id);
        return R.ok(strings);

    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "项目id", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "reportId", value = "报告Id", dataType = "int"),
    })
    @ApiOperation("查询体检报告详细信息的所属项目的结果")
    @PostMapping("/queryByPatientId")
    public R queryByPatientId(@RequestParam Integer id,@RequestParam Integer reportId){
        List<ItemsResultDto> itemsDtos = this.medicalService.queryByIndicatorId(id,reportId);
        return R.ok(itemsDtos);
    }
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }


}
